a = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
b = input().split()
try:
    b = int("".join(map(lambda x: a[x], b)))
except Exception:
    print("Wrong input")
    exit(1)

def is_prime(b: int):
    for i in range(2, b):
        if b % i == 0:
            return False

    return True

less_prime = b
bigger_prime = b

while not is_prime(less_prime):
    less_prime -= 1

while not is_prime(bigger_prime):
    bigger_prime += 1

if b - less_prime < bigger_prime - b:
    print(less_prime)
else:
    print(bigger_prime)
